//
//  IZHIMChatManager.h
//  ZHIMCore
//
//  Created by Chen Zhangli on 2021/1/18.
//

#import <Foundation/Foundation.h>
#import "ZHIMChatManagerDelegate.h"
#import "ZHIMConversation.h"
#import "ZHIMMessage.h"

@protocol IZHIMChatManager <NSObject>

/// 添加回调代理
/// @param delegate 要添加的代理
- (void)addDelegate:(id<ZHIMChatManagerDelegate>)delegate;


/// 移除回调代理
/// @param delegate 要移除的代理
- (void)removeDelegate:(id<ZHIMChatManagerDelegate>)delegate;


#pragma mark - 会话

/// 获取所有会话，如果内存中不存在会从DB中加载
- (NSArray *)getAllConversations;


/// 获取一个会话
/// @param conversationId 会话Id
/// @param type 会话类型
/// @param aIfCreate 如果不存在是否创建
- (ZHIMConversation *)getConversation:(NSString *)conversationId type:(NSInteger)type createIfNotExist:(BOOL)aIfCreate;


/// 删除会话
/// @param conversation 会话
- (void)deleteConversation:(ZHIMConversation *)conversation completion:(void (^)(NSError *error))completion;


/// 会话的消息全部已读
/// @param conversation 会话
- (void)readConversation:(ZHIMConversation *)conversation completion:(void (^)(NSError *error))completion;


#pragma mark - 消息

/// 获取一条消息
/// @param messageId 消息Id
- (ZHIMMessage *)getMessageWithMessageId:(NSString *)messageId;


/// 发送消息已读回执
/// @param messageId 消息Id
/// @param completion 完成的回调
- (void)sendMessageReadAck:(NSString *)messageId completion:(void (^)(NSError *error))completion;


/// 撤回消息
/// @param messageId 消息Id
/// @param completion 完成的回调
- (void)recallMessageWithMessageId:(NSString *)messageId completion:(void (^)(NSError *error))completion;


/// 发送消息
/// @param message 消息
/// @param progress 附件上传进度回调
/// @param completion 发送完成回调
- (ZHIMMessage *)sendMessage:(ZHIMMessage *)message progress:(void (^)(NSProgress *progress))progress completion:(void (^)(ZHIMMessage *message, NSError *error))completion;


/// 重新发送消息
/// @param message 消息
/// @param progress 附件上传进度回调
/// @param completion 发送完成回调
- (void)resendMessage:(ZHIMMessage *)message progress:(void (^)(NSProgress *progress))progress completion:(void (^)(ZHIMMessage *message, NSError *error))completion;



/// 转发消息
/// @param message 被转发的消息
/// @param progress 附件上传进度回调
/// @param conversation 转发到的会话
/// @param completion 发送完成回调
- (void)forwardMessage:(ZHIMMessage *)message to:(ZHIMConversation *)conversation progress:(void (^)(NSProgress *progress))progress completion:(void (^)(ZHIMMessage *message, NSError *error))completion;


/// 查询某个会话的消息
/// @param pageIndex 页码
/// @param conversation 会话
/// @param completion 查询完成的回调
- (void)getMessagesAtPage:(NSInteger)pageIndex inConversation:(ZHIMConversation *)conversation completion:(void (^)(NSArray <ZHIMMessage *> *messages, NSError *error))completion;


/// 查询某个会话的消息
/// @param pageIndex 页码
/// @param conversation 会话
/// @param conditions 条件
/// @param completion 查询完成的回调
- (void)getMessagesAtPage:(NSInteger)pageIndex inConversation:(ZHIMConversation *)conversation withConditions:(NSString *)conditions completion:(void (^)(NSArray <ZHIMMessage *> *messages, NSError *error))completion;


/// 查询某个会话的消息
/// @param startTime 开始时间
/// @param pageSize 每页条数（pageSize >0 往前查找, 反之往后查找）
/// @param conversation 会话
/// @param completion 查询完成的回调
- (void)getMessagesFromTime:(NSTimeInterval)startTime pageSize:(NSInteger)pageSize inConversation:(ZHIMConversation *)conversation completion:(void (^)(NSArray <ZHIMMessage *> *messages, NSError *error))completion;


/// 删除某个会话的消息
/// @param conversationId 会话Id
- (BOOL)deleteMessagesByConversationId:(NSString *)conversationId;


/// 删除某条消息
/// @param message 消息
- (BOOL)deleteMessage:(ZHIMMessage *)message;


/// 按月分组查询某个会话的消息
/// @param type 消息类型
/// @param conversation 会话
- (NSArray *)getSectionMessagesByMonth:(ZHIMMessageType)type inConversation:(ZHIMConversation *)conversation;


/// 按月分组查询某个会话的(图片/视频)消息
/// @param conversation 会话
- (NSArray *)getSectionMediaMessagesByMonthInConversation:(ZHIMConversation *)conversation;


/// 根据关键字搜索文本消息
/// @param keywords 关键字
/// @param conversation 会话
- (NSArray <ZHIMMessage *> *)getMessagesByKeywords:(NSString *)keywords inConversation:(ZHIMConversation *)conversation;


@end
